package com.meeting.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = -1133637474601003587L;

    /**
     * 接口是否成功
     */
    private Boolean success;

    /**  
     * 接口响应状态码  
     */  
    private Integer code;  
  
    /**  
     * 接口响应信息  
     */  
    private String message;
  
    /**  
     * 接口响应的数据  
     */  
    private T data;

    // 成功响应信息
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>();
        result.setCode(200);
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    // 不包含数据的成功响应信息
    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.setCode(200);
        result.setSuccess(true);
        return result;
    }

    // 失败响应信息
    public static <T> Result<T> fail(T data) {
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(500);
        result.setSuccess(false);
        return result;
    }

    // 失败响应信息，自定义响应码
    public static <T> Result<T> fail(T data, int code) {
        Result<T> result = new Result<T>();
        result.setData(data);
        result.setCode(code);
        result.setSuccess(false);
        return result;
    }

    // 带消息的失败响应信息
    public static <T> Result<T> fail(String message) {
        Result<T> result = new Result<T>();
        result.setMessage(message);
        result.setCode(500);
        result.setSuccess(false);
        return result;
    }
}    
